home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqdisplay / surface16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-10  |  3.1 KB  |  97 lines

  1. static void BuildSky16(unsigned short int *out, unsigned char *in)
  2. {
  3.   int size;
  4.  
  5.   for (size = (SKY_X * SKY_Y) - 1; size >= 0; size--) {
  6.     struct rgb *pel = &cachedPalette[*in++];
  7.  
  8.     /*unsigned short int red = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 5)); */
  9.     /*unsigned short int green = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 6)); */
  10.     /*unsigned short int blue = ((unsigned short int)(*((unsigned char *)pel)) >> (8 - 5)); */
  11.     /**out++ = (red << (6 + 5)) | (green << 5) | (blue); */
  12.     *out++ = (((unsigned short int)(pel->r) >> (8 - 5)) << (6 + 5)) |
  13.       (((unsigned short int)(pel->g) >> (8 - 6)) << 5) |
  14.       (((unsigned short int)(pel->b) >> (8 - 5)));
  15.   }
  16. }
  17.  
  18. static void BuildLightBlock16(unsigned short int *out, struct bitmap *raw, int x, int y)
  19. {
  20.   int c, dc;
  21.   int a, b, h, c0, c1, c2, c3;
  22.   int y_max = raw->height, x_max = raw->width;
  23.   unsigned char *fullbright = raw->data + lookup(y, raw->width);
  24.  
  25.   c0 = ((255 << 6) - lightmapIndex[0]);
  26.   c1 = ((255 << 6) - lightmapIndex[1]);
  27.   c2 = ((255 << 6) - lightmapIndex[lightmapWidth]);
  28.   c3 = ((255 << 6) - lightmapIndex[lightmapWidth + 1]);
  29.  
  30.   c2 = (c2 - c0) >> shift;
  31.   c3 = (c3 - c1) >> shift;
  32.  
  33.   for (b = 0; b < step; ++b) {
  34.     h = x;
  35.     c = c0;
  36.     dc = (c1 - c0) >> shift;
  37.     for (a = 0; a < step; ++a) {
  38.       struct rgb *pel = &cachedPalette[fullbright[h]];
  39.       unsigned short int red = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 5));
  40.       unsigned short int green = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 6));
  41.       unsigned short int blue = ((unsigned short int)(*((unsigned char *)pel)) >> (8 - 5));
  42.  
  43.       /*if((red = (red * c) >> (5 + 8)) > 0x1F) */
  44.       /*  red = 0x1F; */
  45.       /*if((green = (green * c) >> (5 + 8)) > 0x1F) */
  46.       /*  green = 0x1F; */
  47.       /*if((blue = (blue * c) >> (5 + 8)) > 0x1F) */
  48.       /*  blue = 0x1F; */
  49.       *out++ = (red << 11) | (green << 5) | (blue);
  50.       c += dc;
  51.       if (++h == x_max)
  52.     h = 0;
  53.     }
  54.     out += row;
  55.     c0 += c2;
  56.     c1 += c3;
  57.     if (++y == y_max) {
  58.       y = 0;
  59.       fullbright = raw->data;
  60.     }
  61.     else
  62.       fullbright += raw->width;
  63.   }
  64. }
  65.  
  66. static unsigned short int brightColorshift;
  67. static void BuildBrightBlock16(unsigned short int *out, struct bitmap *raw, int x, int y)
  68. {
  69.   int a, b, h;
  70.   int y_max = raw->height, x_max = raw->width;
  71.   unsigned char *fullbright = raw->data + lookup(y, raw->width);
  72.  
  73.   for (b = 0; b < step; ++b) {
  74.     h = x;
  75.     for (a = 0; a < step; ++a) {
  76.       struct rgb *pel = &cachedPalette[fullbright[h]];
  77.       unsigned short int red = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 5));
  78.       unsigned short int green = ((unsigned short int)(*((unsigned char *)pel)++) >> (8 - 6));
  79.       unsigned short int blue = ((unsigned short int)(*((unsigned char *)pel)) >> (8 - 5));
  80.  
  81.       /*red = red >> brightColorshift; */
  82.       /*green = green >> brightColorshift; */
  83.       /*blue = blue >> brightColorshift; */
  84.       *out++ = (red << 11) | (green << 5) | (blue);
  85.       if (++h == x_max)
  86.     h = 0;
  87.     }
  88.     out += row;
  89.     if (++y == y_max) {
  90.       y = 0;
  91.       fullbright = raw->data;
  92.     }
  93.     else
  94.       fullbright += raw->width;
  95.   }
  96. }
  97.